Skip to content

Conversation

@joboet
Copy link
Member

@joboet joboet commented Mar 23, 2024

expose_addr is a bad name, an address is just a number and cannot be exposed. The operation is actually about the provenance of the pointer.

This PR thus changes the name of the method to expose_provenance without changing its return type. There is sufficient precedence for returning a useful value from an operation that does something else without the name indicating such, e.g. Option::insert and MaybeUninit::write.

Returning the address is merely convenient, not a fundamental part of the operation. This is implied by the fact that integers do not have provenance since

let addr = ptr.addr();
ptr.expose_provenance();
let new = ptr::with_exposed_provenance(addr);

must behave exactly like

let addr = ptr.expose_provenance();
let new = ptr::with_exposed_provenance(addr);

as the result of ptr.expose_provenance() and ptr.addr() is the same integer. Therefore, this PR removes the #[must_use] annotation on the function and updates the documentation to reflect the important part.

An alternative name would be expose_provenance. I'm not at all opposed to that, but it makes a stronger implication than we might want that the provenance of the pointer returned by ptr::with_exposed_provenance1 is the same as that what was exposed, which is not yet specified as such IIUC. IMHO expose does not make that connection.

A previous version of this PR suggested expose as name, libs-api decided on expose_provenance to keep the symmetry with with_exposed_provenance.

CC @RalfJung
r? libs-api

Footnotes

  1. I'm using the new name for from_exposed_addr suggested by rename ptr::from_exposed_addr -> ptr::with_exposed_provenance #122935 here.

@joboet joboet added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. A-strict-provenance Area: Strict provenance for raw pointers labels Mar 23, 2024
@rustbot rustbot added O-hermit Operating System: Hermit O-itron Operating System: ITRON S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 23, 2024
@rustbot
Copy link
Collaborator

rustbot commented Mar 23, 2024

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred to the platform-builtins intrinsics. Make sure the
LLVM backend as well as portable-simd gets adapted for the changes.

cc @antoyo, @GuillaumeGomez, @bjorn3, @calebzulawski, @programmerjake

This PR changes Stable MIR

cc @oli-obk, @celinval, @ouz-a

Portable SIMD is developed in its own repository. If possible, consider making this change to rust-lang/portable-simd instead.

cc @calebzulawski, @programmerjake

This PR changes MIR

cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member

An alternative name would be expose_provenance. I'm not at all opposed to that, but it makes a stronger implication than we might want that the provenance of the pointer returned by ptr::with_exposed_provenance1 is the same as that what was exposed, which is not yet specified as such IIUC. IMHO expose does not make that connection.

I don't see how that implication would be any stronger by saying expose_provenance rather than expose.

The main benefit of expose is that it is less long. :)

@rustbot
Copy link
Collaborator

rustbot commented Mar 23, 2024

The Miri subtree was changed

cc @rust-lang/miri


let val = match *kind {
mir::CastKind::PointerExposeAddress => {
mir::CastKind::PointerExpose => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW in MiniRust I got rid of this "expose cast", and instead made expose something more like a NonDivergingIntrinsic. That properly reflects that it is entirely decoupled. But ofc that is hard to translate to LLVM...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmh, actually... Since currently we generate ptrtoint for every conversion, including addr, we might be able to add a new intrinsic for exposing that lowers to a noop in LLVM, but can get recognized in miri, and then write expose as

intrinsics::expose(ptr);
ptr.addr()

Copy link
Member

@RalfJung RalfJung Mar 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since currently we generate ptrtoint for every conversion, including addr

Not anymore: #121282.

EDIT: Ah no that's the other direction. Still, this is not something I'd like to rely on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we could indeed make it an intrinsic. As a cast it is kind of an odd duck, none of our other casts has a side-effect. All other casts can be removed when their result is unused.

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum CastKind {
PointerExposeAddress,
PointerExpose,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't rename it here. Thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then where should we put the note to rename it in the future? It's quite annoying when we clean up naming but smir still uses old (and thus more confusing / less apt) names possibly indefinitely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document the field instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's just a comment it will get lost. It needs to carry at least some sort of marker so that when you eventually do follow suit and fix old confusing names in smir, you can reliably find them. Something one can grep for. Like FIXME(smir-rename) or so -- I don't care about the details, but I hope the smir team can come up with a plausible process and document it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment with FIXME(smir-rename). And just fyi, #122935 made this kind of change but didn't get caught 😄.

@Amanieu
Copy link
Member

Amanieu commented Apr 2, 2024

We discussed this in the libs-api meeting and we prefer expose_provenance as a method name for the symmetry with with_exposed_provenance.

@bors
Copy link
Collaborator

bors commented Apr 3, 2024

☔ The latest upstream changes (presumably #123396) made this pull request unmergeable. Please resolve the merge conflicts.

@joboet joboet changed the title Rename expose_addr to expose Rename expose_addr to expose_provenance Apr 3, 2024
@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member

RalfJung commented Apr 3, 2024

I have updated the PR description to match, feel free to tweak it further.

@Amanieu
Copy link
Member

Amanieu commented Apr 3, 2024

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 3, 2024

📌 Commit 989660c has been approved by Amanieu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 3, 2024
@bors bors merged commit 80d592c into rust-lang:master Apr 3, 2024
@rustbot rustbot added this to the 1.79.0 milestone Apr 3, 2024
@joboet joboet deleted the pointer_expose branch April 3, 2024 22:49
@dtolnay dtolnay removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-strict-provenance Area: Strict provenance for raw pointers O-hermit Operating System: Hermit O-itron Operating System: ITRON S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants